package com.example.bookdemo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bookdemo.domain.Book;
import com.example.bookdemo.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ Author:郭子木
 * @ Date:2022/6/7
 * @ Time:17:19
 * @ Name:ControllerBook
 * @ Description:
 */
//@RestController
//@RequestMapping("/books")
public class ControllerBook_bak {
    @Autowired
    private IBookService iBookService;

    @GetMapping
    public List<Book> getAll()
    {
        return iBookService.list();
    }
    @GetMapping("/hello")
    public String Hello()
    {
        return "hello word";
    }

    @PostMapping
    public Boolean save(@RequestBody Book book)
    {
        return iBookService.save(book);
    }

    @PutMapping
    public Boolean update(@RequestBody Book book)
    {
        return iBookService.updateById(book);
    }

    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable Integer id)
    {
        return iBookService.delete(id);
    }

    @GetMapping("{id}")
    public Book getById(@PathVariable Integer id)
    {
        return iBookService.getById(id);
    }

    @GetMapping("{currentPage}/{pageSize}")
    public IPage<Book> getPage(@PathVariable int currentPage,@PathVariable int pageSize)
    {
        return iBookService.getPage(currentPage,pageSize);
    }
}
